using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Spread.Common.Features.Sample;
using Spread.Common.DataStore;
using FarPoint.Win;
using GrapeCity.Spreadsheet;

namespace Spread.Calculation.Features
{
    public partial class BasicFunctionDemo : BaseSampleControl
    {
        public BasicFunctionDemo()
        {
            InitializeComponent();
            SetUpSpreadSheet();
        }
        private void SetUpSpreadSheet()
        {
            Name = "Basic Functions";
            sheetView.DataAutoSizeColumns = false;
            sheetView.Rows.Default.Height = 30;
            sheetView.Columns.Default.Width = 90;
            sheetView.DataSource = new DataService().JsonDataSource.GetMovieRecords();
            
            sheetView.Columns.Add(sheetView.Columns.Count, 2);
            sheetView.Cells[1, sheetView.Columns.Count - 2].Value = "Audience Maximum Score";
            sheetView.Cells[2, sheetView.Columns.Count - 2].Value = "Audience Minimum Score";
            sheetView.Cells[3, sheetView.Columns.Count - 2].Value = "Audience Average Score";

            sheetView.Cells[1, sheetView.Columns.Count - 1].Formula = "MAX(D1:D74)";
            sheetView.Cells[2, sheetView.Columns.Count - 1].Formula = "MIN(D1:D74)";
            sheetView.Cells[3, sheetView.Columns.Count - 1].Formula = "AVERAGE(D1:D74)";

            sheetView.Cells[6, sheetView.Columns.Count - 2].Value = "Maximum Rating";
            sheetView.Cells[7, sheetView.Columns.Count - 2].Value = "Minimum Rating";
            sheetView.Cells[8, sheetView.Columns.Count - 2].Value = "Average Rating";

            sheetView.Cells[6, sheetView.Columns.Count - 1].Formula = "MAX(F1:F74)";
            sheetView.Cells[7, sheetView.Columns.Count - 1].Formula = "MIN(F1:F74)";
            sheetView.Cells[8, sheetView.Columns.Count - 1].Formula = "AVERAGE(F1:F74)";
            sheetView.Columns[sheetView.Columns.Count - 1].Width = 110;
            sheetView.Columns[sheetView.Columns.Count - 2].Width = 150;

            for(int column = sheetView.Columns.Count - 2; column < sheetView.Columns.Count; column++)
            {
                for(int row = 1; row < 4; row++)
                {
                    sheetView.Cells[row, column].BackColor = System.Drawing.Color.LightGreen;
                    sheetView.Cells[row + 5, column].BackColor = System.Drawing.Color.LightBlue;
                    sheetView.Cells[row + 5, column].Border = sheetView.Cells[row, column].Border = new LineBorder(System.Drawing.Color.Black, 2, column == sheetView.Columns.Count - 2, row == 1, column == sheetView.Columns.Count - 1, row == 3);
                }
            }
            spread.DefaultSkin = FarPoint.Win.Spread.DefaultSpreadSkins.Office2016Colorful;
            for (int c = 0; c < sheetView.ColumnCount; c++)
                spread.AsWorkbook().Worksheets[0].Columns[c].AutoFit();
        }
    }
}


//
//BasicFunctionDemo.Designer.cs
//


namespace Spread.Calculation.Features
{
    partial class BasicFunctionDemo
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.panelFormulaBar = new System.Windows.Forms.Panel();
            this.splitContainer1 = new System.Windows.Forms.SplitContainer();
            this.nameBox1 = new FarPoint.Win.Spread.NameBox();
            this.formulaTextBox1 = new FarPoint.Win.Spread.FormulaTextBox();
            this.spread = new FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None);
            this.sheetView = new FarPoint.Win.Spread.SheetView();
            this.pnlMain.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.spread)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.sheetView)).BeginInit();
            this.SuspendLayout();
            // 
            // pnlMain
            // 
            this.pnlMain.Controls.Add(this.spread);
            this.pnlMain.Controls.Add(this.panelFormulaBar);
            // 
            // panelFormulaBar
            // 
            this.panelFormulaBar.Controls.Add(this.splitContainer1);
            this.panelFormulaBar.Dock = System.Windows.Forms.DockStyle.Top;
            this.panelFormulaBar.Location = new System.Drawing.Point(0, 24);
            this.panelFormulaBar.Name = "panelFormulaBar";
            this.panelFormulaBar.Size = new System.Drawing.Size(800, 23);
            this.panelFormulaBar.TabIndex = 6;
            // 
            // splitContainer1
            // 
            this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.splitContainer1.Location = new System.Drawing.Point(0, 0);
            this.splitContainer1.Name = "splitContainer1";
            // 
            // splitContainer1.Panel1
            // 
            this.splitContainer1.Panel1.Controls.Add(this.nameBox1);
            this.splitContainer1.Panel1MinSize = 121;
            // 
            // splitContainer1.Panel2
            // 
            this.splitContainer1.Panel2.Controls.Add(this.formulaTextBox1);
            this.splitContainer1.Size = new System.Drawing.Size(800, 23);
            this.splitContainer1.SplitterDistance = 121;
            this.splitContainer1.TabIndex = 0;
            // 
            // nameBox1
            // 
            this.nameBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.nameBox1.Location = new System.Drawing.Point(0, 0);
            this.nameBox1.MaxLength = 255;
            this.nameBox1.Name = "nameBox1";
            this.nameBox1.Size = new System.Drawing.Size(121, 21);
            this.nameBox1.TabIndex = 0;
            // Attach nameBox1 to spread
            this.nameBox1.Attach(this.spread);
            // 
            // formulaTextBox1
            // 
            this.formulaTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.formulaTextBox1.Location = new System.Drawing.Point(0, 0);
            this.formulaTextBox1.Multiline = false;
            this.formulaTextBox1.Name = "formulaTextBox1";
            this.formulaTextBox1.Size = new System.Drawing.Size(675, 23);
            this.formulaTextBox1.TabIndex = 0;
            // Attach formulaTextBox1 to spread
            this.formulaTextBox1.Attach(this.spread);
            // 
            // spread
            // 
            this.spread.AccessibleDescription = "";
            this.spread.Dock = System.Windows.Forms.DockStyle.Fill;
            this.spread.Location = new System.Drawing.Point(0, 0);
            this.spread.Name = "spread";
            this.spread.Sheets.AddRange(new FarPoint.Win.Spread.SheetView[] {
            this.sheetView});
            this.spread.Size = new System.Drawing.Size(477, 487);
            this.spread.TabIndex = 0;
            // 
            // sheetView
            // 
            this.sheetView.Reset();
            this.sheetView.SheetName = "Sheet1";
            // Formulas and custom names must be loaded with R1C1 reference style
            this.sheetView.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;
            this.sheetView.RowHeader.Columns.Default.Width = 35F;
            this.sheetView.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1;
            // 
            // BasicFunctionDemo
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Name = "BasicFunctionDemo";
            this.pnlMain.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.spread)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.sheetView)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.SplitContainer splitContainer1;
        protected internal System.Windows.Forms.Panel panelFormulaBar;
        protected internal FarPoint.Win.Spread.NameBox nameBox1;
        protected internal FarPoint.Win.Spread.FormulaTextBox formulaTextBox1;
        private FarPoint.Win.Spread.FpSpread spread;
        private FarPoint.Win.Spread.SheetView sheetView;
    }
}
